home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / amiga / v3_1 / sbp3_1e.lzh / PRINTABL.PL < prev    next >
Text File  |  1991-10-31  |  1KB  |  45 lines

  1. /* From the book PROLOG PROGRAMMING IN DEPTH
  2.    by Michael A. Covington, Donald Nute, and Andre Vellino.
  3.    Copyright 1988 Scott, Foresman & Co.
  4.    Non-commercial distribution of this file is permitted. */
  5. /* Modified for Quintus Prolog by Andreas Siebert */
  6.  
  7. /* PRINTABL.PL */
  8.  
  9. /*
  10.  * print_table(Proc,Start,Finish,Step)
  11.  *   Prints a table of the mathematical function
  12.  *   computed by Proc, which is a lambda-expression
  13.  *   (see text), for input values from Start to
  14.  *   Finish at intervals of Step.
  15.  */
  16.  
  17. print_table(_,Start,Finish,_) :-
  18.   Start > Finish,
  19.   !.
  20.  
  21. print_table(lambda(Input,Result,Goal),Start,Finish,Step) :-
  22.   write(Start),
  23.   write('  '),
  24.   prove_and_discard_instantiations(
  25.      ( Input = Start, call(Goal), write(Result), nl )
  26.                                   ),
  27.   NewStart is Start+Step,
  28.   print_table(lambda(Input,Result,Goal),NewStart,Finish,Step).
  29.  
  30.  
  31. /*
  32.  * prove_and_discard_instantiations(Goal)
  33.  *   Like call(Goal), except that any instantiations
  34.  *   done during execution are undone upon exit.
  35.  */
  36.  
  37. prove_and_discard_instantiations(Goal) :-
  38.                                     \+ \+ call(Goal).
  39.  
  40. /*
  41.  * Demonstration of the above
  42.  */
  43.  
  44. demo :- print_table(lambda(X,Y,(Y is 3*X*X)), 0.0, 1.0, 0.1).
  45.